package com.itrencai.d18_reflect_class;

import org.junit.Test;

import java.lang.reflect.Constructor;
import java.util.concurrent.locks.Condition;

public  class Test2{
    @Test
    public void getDeclaredConstructor() throws Exception {
        //1.调用构造器得到一个类的对象返回
        //a.第一步，获取对象
        Class c=Student.class;
        //b.定位单个构造器对象（按照参数定位无参构造器）
        Constructor cons=c.getDeclaredConstructor();
        System.out.println(cons.getName()+"==>"+cons.getParameterCount());
        //遇到私有构造器可以暴力反射
        cons.setAccessible(true);// 暴力打开权限权限被打开了
        Student s=(Student) cons.newInstance();
        System.out.println(s);
        //c.定位某个有参构造器
        Constructor cons1=c.getDeclaredConstructor(String.class,int.class);
        System.out.println(cons1.getName()+"==>"+cons1.getParameterCount());
        Student s1= (Student) cons1.newInstance("孙悟空",1000);
       }


}
